<?php

namespace app\index\controller\trade;

use app\index\model\UM as UM;
use app\index\service\RecentTradeService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use think\APP;
use think\Request as Request;

/**
 * RecentTrade 控制器
 * Class RecentTrade
 * @package app\index\controller\trade;
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 * @see \app\index\validate\trade\RecentTrade
 */
class RecentTrade
{
    // 请求参数
    private Request $request;

    // service
    private RecentTradeService $service;

    public function __construct(Request $request, RecentTradeService $recentTradeService)
    {
        $this->request = $request;
        $this->service = $recentTradeService;
    }

    /**
     * 详情
     * @param UM|null $user
     * @return ApiResponse
     * @url /trade/recent_trade/read
     */
    public function read(?UM $user): ApiResponse
    {
        $request = $this->request;

        $data = null;
        if (!is_null($user)) {
            $data = $this->service->read($user);
        }

        return ApiResponse::success($data);
    }
}
